/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var sortList = function (head) {
    if (head == null || head.next == null) {
        return head
    }
    let arr = []
    let p = head
    while (p) {
        arr.push(p)
        p = p.next
    }
    arr.sort((a, b) => a.val - b.val)
    arr.forEach((item, index) => {
        if (index == arr.length - 1)
            item.next = null
        else item.next = arr[index + 1]
    })
    return arr[0]
};